home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ptv1n2.arc / VARDUMP.BAS < prev    next >
BASIC Source File  |  1990-06-14  |  4KB  |  133 lines

  1. DECLARE SUB DumpLine (Offset%, NumBytes%, FileNum%)
  2. DECLARE SUB PrintHeader (FileNum AS INTEGER)
  3. DECLARE SUB PrintBottom (FileNum AS INTEGER)
  4. DEFINT A-Z
  5.  
  6. '-------------------------------------------
  7. ' DumpLine(Offset%, NumBytes%)
  8. ' Dump one line of bytes to the device file.
  9. ' Offset is the starting byte position, and
  10. ' NumBytes is the number of bytes to print.
  11. '-------------------------------------------
  12. SUB DumpLine (Offset, NumBytes, FileNum%)
  13.   'Print the left edge
  14.   PRINT #FileNum%, "   "; CHR$(186); " ";
  15.  
  16.   ' Hex Loop
  17.   FOR I = 0 TO NumBytes - 1
  18.     ch$ = HEX$(PEEK(Offset + I))
  19.     IF LEN(ch$) = 1 THEN ch$ = "0" + ch$
  20.     PRINT #FileNum%, ch$; " ";
  21.   NEXT I
  22.  
  23.   ' Add Padding if necessary so separators will be aligned
  24.   FOR I = 0 TO (48 - (NumBytes * 3)) - 1
  25.     PRINT #FileNum%, " ";
  26.   NEXT I
  27.   PRINT #FileNum%, CHR$(179);
  28.  
  29.   ' ASCII Loop
  30.   FOR I = 0 TO NumBytes - 1
  31.     ch = PEEK(Offset + I)
  32.     ' Filter out control chars and graphic chars
  33.     IF (ch < 32) OR (ch > 127) THEN ch = ASC(".")
  34.     PRINT #FileNum%, CHR$(ch);
  35.   NEXT I
  36.  
  37.   ' Add padding if necessary so right edge will be aligned
  38.   PRINT #FileNum%, SPACE$(16 - NumBytes);
  39.  
  40.   ' Print right edge
  41.   PRINT #FileNum%, CHR$(186)
  42. END SUB
  43.  
  44. '------------------------------------------------
  45. ' Print the bottom line of the variable dump box.
  46. '------------------------------------------------
  47. SUB PrintBottom (FileNum AS INTEGER)
  48.   PRINT #FileNum%, "   "; CHR$(200); STRING$(49, 205); CHR$(207);
  49.   PRINT #FileNum%, STRING$(16, 205); CHR$(188)
  50.   ' The space is included for some printers that won't simply
  51.   ' print a blank line.
  52.   PRINT #FileNum%, " "
  53. END SUB
  54.  
  55. '-------------------------------------------
  56. 'Print the Header for the variable dump box.
  57. '-------------------------------------------
  58. SUB PrintHeader (FileNum AS INTEGER)
  59.   PRINT #FileNum%, "   "; CHR$(201); STRING$(49, 205);
  60.   PRINT #FileNum%, CHR$(209); STRING$(16, 205); CHR$(187)
  61.   PRINT #FileNum%, "   "; CHR$(186); " ";
  62.   FOR I = 0 TO 15
  63.     PRINT #FileNum%, "0"; HEX$(I); " ";
  64.   NEXT I
  65.   PRINT #FileNum%, CHR$(179);
  66.   FOR I = 0 TO 15
  67.     PRINT #FileNum%, HEX$(I);
  68.   NEXT I
  69.   PRINT #FileNum%, CHR$(186)
  70.   PRINT #FileNum%, "   "; CHR$(199); STRING$(49, 196); CHR$(197);
  71.   PRINT #FileNum%, STRING$(16, 196); CHR$(182)
  72. END SUB
  73.  
  74. '------------------------------------------------------
  75. ' Sub VarDump(Target AS ANY, ItSize AS INTEGER)
  76. '
  77. ' VarDump will provide a hex dump of ANY Variable.
  78. ' The display will consist of 16 lines of hex
  79. ' digits followed by a separator, and then 16 ASCII
  80. ' characters.
  81. '
  82. ' Device$ is the target device and can be either
  83. ' a file name (watch it, duplicate files will be
  84. ' overwritten, there is no test to see if the file
  85. ' already exists!) or one of the following device
  86. ' names: SCRN: COMn: LPTn:
  87. ' where n is the number of the device for instance,
  88. ' COM2: or LPT1:
  89. '
  90. ' Target is the Address of the Variable
  91. ' Use VARPTR to obtain the address of a User
  92. ' Defined variable, a Fixed Length String,
  93. ' any numeric variable, or a Dynamic String's
  94. ' String Descriptor. Use SADD to look at a
  95. ' Dynamic String.
  96. '
  97. ' ItSize is the Size in bytes of the variable
  98. ' use Len(Target) to obtain the size in bytes of
  99. ' a User Defined Variable, or any string. Use
  100. ' 2 for an INTEGER, 4 for a LONG, 4 for Single
  101. ' Precision, 8 bytes for Double precision, and
  102. ' 4 for a String Descriptor.
  103. '------------------------------------------------------
  104. SUB VarDump (Device$, Target, ItSize AS INTEGER)
  105. CONST True = -1, False = NOT True
  106.   ' Full will indicate how many full lines to display
  107.   ' LeftOver will indicate how many bytes are left over
  108.   ' to be displayed on the last line.
  109.   Full = ItSize \ 16
  110.   LeftOver = ItSize MOD 16
  111.   FileNum% = FREEFILE
  112.  
  113.   OPEN Device$ FOR OUTPUT AS #FileNum%
  114.  
  115.   ' Print the line of reference numbers and a separator line
  116.   CALL PrintHeader(FileNum%)
  117.  
  118.   'Loop to display the full lines
  119.  
  120.   FOR I = 0 TO Full - 1
  121.     CALL DumpLine((Target + (I * 16)), 16, FileNum%)
  122.   NEXT I
  123.  
  124.   ' Loop to print leftover bytes
  125.   IF LeftOver > 0 THEN
  126.     CALL DumpLine((Target + (Full * 16)), LeftOver, FileNum%)
  127.   END IF
  128.  
  129.   CALL PrintBottom(FileNum%)
  130.   CLOSE 1
  131. END SUB
  132.  
  133.